<div class="layuimini-main">

	<div class="layui-form layuimini-form">
		<div class="layui-form-item">
			<label class="layui-form-label required">旧密码</label>
			<div class="layui-input-block">
				<input type="password" name="oldPassword" lay-verify="required" lay-reqtext="旧密码不能为空" placeholder="请输入旧登录密码"  value="" class="layui-input">
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label required">新密码</label>
			<div class="layui-input-block">
				<input type="password" name="password" lay-verify="required" lay-reqtext="新密码不能为空" placeholder="请输入新登录密码"  value="" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label required">确认新密码</label>
			<div class="layui-input-block">
				<input type="password" name="confirmPassword" lay-verify="required" lay-reqtext="确认新密码不能为空" placeholder="请再次输入新登录密码"  value="" class="layui-input">
			</div>
		</div>

		<div class="layui-form-item">
			<div class="layui-input-block">
				<button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
			</div>
		</div>
	</div>
</div>
<script>
    layui.use(['form','miniPage'], function () {
        var form = layui.form,
            layer = layui.layer,
             miniPage = layui.miniPage,
			$ = layui.$;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
			var password = data.field.password;
			var confirmPassword = data.field.confirmPassword;
			if(confirmPassword != password){
				layer.msg("新密码和确认新不一致", {icon: 5, shift: 6});
				return false;
			}
			data.field.oldPassword = data.field.oldPassword.md5(32).toUpperCase();
			data.field.password = password.md5(32).toUpperCase();
			data.field.confirmPassword = data.field.password;
            
			$.ajax({
				url: '/sysUser/updatePassword',
				type: 'POST',
				dataType: "json",
				contentType: 'application/json;charset=UTF-8',
				data: JSON.stringify(data.field),
				success: function(data){
					if(data.code != "000000"){
						layer.msg(data.message, {icon: 5, shift: 6});
						return false;
					}
					layer.msg("修改成功，请重新登录", {
						icon: 1,
						time: 1000,
						shade: 0.01,
						shadeClose: false}, function(){
						//回到欢迎页面
						//miniPage.hashHome();
						//跳转到首页
						window.location = '/page/login.html';
					});
					return false;
				},
				error: function(data){
					layer.msg(data.message, {icon: 5, shift: 6});
				}
			});
			
            return false;
        });

    });
</script>